package math

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
	"reflect"
	"strings"
)

type MULTIPLUS[T interface{}] struct {
	base.NoOperandsInstruction
}

func (self *MULTIPLUS[T]) Execute(jFrame *rtda.JFrame) {
	stack := jFrame.OperandStack()
	e := reflect.TypeOf(self).Elem().String()
	etype := strings.ReplaceAll(strings.Split(e, "[")[1], "]", "")
	switch etype {
	case "int64":
		stack.PushLong(stack.PopLong() * stack.PopLong())
		break
	case "int32":
		stack.PushInt(stack.PopInt() * stack.PopInt())
		break
	case "float32":
		stack.PushFloat(stack.PopFloat() * stack.PopFloat())
		break
	case "float64":
		stack.PushDouble(stack.PopDouble() * stack.PopDouble())
		break
	}
}

type DMUL struct {
	MULTIPLUS[float64]
}

type FMUL struct {
	MULTIPLUS[float32]
}

type IMUL struct {
	MULTIPLUS[int32]
}

type LMUL struct {
	MULTIPLUS[int64]
}
